package com.softeem.score.manager.controller.admin;


import com.github.pagehelper.PageInfo;
import com.softeem.score.common.log.annotation.Log;
import com.softeem.score.common.log.enums.OperatorType;
import com.softeem.score.manager.service.ClassesService;
import com.softeem.score.model.dto.ClassesDto;
import com.softeem.score.model.entity.ClassesEntity;
import com.softeem.score.model.entity.school.Classes;
import com.softeem.score.model.vo.common.Result;
import com.softeem.score.model.vo.common.ResultCodeEnum;
import com.softeem.score.model.vo.school.ClassesVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhu
 * @since 2024-02-14
 */
@Tag(name = "班级管理")
@RestController
@RequestMapping("/admin/school/classes")
public class ClassesController {

    @Autowired
    private ClassesService classesService;

    @Operation(summary = "分页查询班级信息")
    @GetMapping("/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<ClassesVo>> findByPage(ClassesDto classesDto,
                                                  @PathVariable(value = "pageNum") Integer pageNum,
                                                  @PathVariable(value = "pageSize") Integer pageSize) {
        PageInfo<ClassesVo> pageInfo = classesService.findByPage(classesDto, pageNum, pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
    @Log(title = "保存班级信息",businessType = 1,operatorType = OperatorType.MANAGE)
    @Operation(summary = "保存班级信息")
    @PostMapping("/saveClasses")
    public Result saveClasses(@RequestBody Classes classes) {
        classesService.saveClasses(classes);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "查询所有班级信息")
    @GetMapping("/findAllClasses")
    public Result<List<ClassesEntity>> findAllClasses(@RequestParam(value = "collegeId", required = false) Long collegeId,
                                                      @RequestParam(value = "majorId", required = false) Long majorId) {
        List<ClassesEntity> allClasses = classesService.findAllClasses(collegeId, majorId);
        return Result.build(allClasses, ResultCodeEnum.SUCCESS);
    }

    @Log(title = "更新班级信息",businessType = 2,operatorType = OperatorType.MANAGE)
    @Operation(summary = "更新班级信息")
    @PutMapping(value = "/updateClasses")
    public Result updateClasses(@RequestBody Classes classes) {
        classesService.updateClasses(classes);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
    @Log(title = "删除班级信息",businessType = 3,operatorType = OperatorType.MANAGE)
    @Operation(summary = "删除班级信息")
    @DeleteMapping(value = "/deleteById/{classesId}")
    public Result deleteById(@PathVariable(value = "classesId") Long classesId) {
        classesService.deleteById(classesId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

}

